mojeW,mojeH = 1360,768
sW,sH = guiGetScreenSize()
sx, sy = (sW/mojeW), (sH/mojeH)
local font = dxCreateFont(":cmta-pobieraniezasobow/OSB.ttf", 20*sx)
local font1 = dxCreateFont(":cmta-pobieraniezasobow/OSB.ttf", 16*sx)
local font2 = dxCreateFont(":cmta-pobieraniezasobow/OSB.ttf", 11*sx)

class "CAchievement"
{
	__init__ = function(self, title)
		self.renderFunc = function() self:onRender() end
		addEventHandler("onClientRender", root, self.renderFunc)

		self.title = title
		self.description = gAchievements[self.title][2]
		self.reward = gAchievements[self.title][1]

		playSound("info.mp3", false)
		czas = getTickCount()
		setTimer(function()
					removeEventHandler("onClientRender", root, self.renderFunc)
		end, 6.5 * 1000, 1)
	end,

	onRender = function(self)
	if (getTickCount()-czas) > 5500 then
		alph = interpolateBetween(255, 0, 0, 0, 0, 0, (getTickCount() - czas)/6500, "Linear")
	else
		alph = interpolateBetween(0, 0, 0, 255, 0, 0, (getTickCount() - czas)/2000, "Linear")
	end    
	    dxDrawImage(570*sx, 40*sy, 220*sx, 155*sy, "icon.png", 0, 0, 0, tocolor(255, 255, 255, alph), false)
        dxDrawText("Zdobyto Osiągnięcie", 480*sx, 135*sy, 880*sx, 300*sy, tocolor(255,215,0, alph), 1.00, font, "center", "center", false, false, false, false, false)
        dxDrawText(self.title, 480*sx, 160*sy, 880*sx, 350*sy, tocolor(192,192,192, alph), 1.00, font1, "center", "center", false, false, false, true, false)
		dxDrawText(self.description, 480*sx, 200*sy, 880*sx, 350*sy, tocolor(120,120,120, alph), 1.00, font2, "center", "center", false, false, false, true, false)
        dxDrawText(""..string.format("+%d PO", self.reward).."", 480*sx, 235*sy, 880*sx, 350*sy, tocolor(192,192,192, alph), 1.00, font2, "center", "center", false, false, false, true, false)
	end,
}

function addAchievement(title)
	if type(title) == "string" then
		return CAchievement(title)
	end
end

function getAchievementDescription(name)
	return gAchievements[name][3]
end

function getAchievementPoints(name)
	return gAchievements[name][2]
end

function onPlayerAchievementGet(title)
	if title then
		addAchievement(title)
	end
end
addEvent("onPlayerAchievementGet", true)
addEventHandler("onPlayerAchievementGet", root, onPlayerAchievementGet)

function addClientAchievement(player, achievement)
	triggerClientEvent("onPlayerAddAchievement", player, player, achievement)
end
